package io.renren.common.gvy;

import groovy.lang.Binding;
import groovy.util.GroovyScriptEngine;
import groovy.util.ResourceException;
import groovy.util.ScriptException;

import java.io.IOException;

public class JavaCallGroovyDemo01 {
    public static void main(String[] args) {
        // 从文件系统或 classpath 加载脚本
        GroovyScriptEngine engine = null; // 脚本目录
        try {
            engine = new GroovyScriptEngine("renren-admin/src/main/resources/groovy-scripts/");
            Binding binding = new Binding();
            binding.setVariable("param1", "abcd");
            binding.setVariable("param2", "defg");

            Object result = engine.run("groovy_script_01.groovy", binding);
            System.out.println(result);
        } catch (IOException e) {
            throw new RuntimeException(e);
        } catch (ScriptException e) {
            throw new RuntimeException(e);
        } catch (ResourceException e) {
            throw new RuntimeException(e);
        }

    }
}
